package redis

import (
	"fmt"
	"github.com/go-redis/redis"
	"github.com/zeromicro/go-zero/core/logx"
	"zeroOne/goods_srv/app_config"
)

var (
	RdbClient *redis.Client
)

func InitRedis() {
	redisConf := app_config.AppConf.RedisConfig
	addr := fmt.Sprintf("%s:%d", redisConf.Host, redisConf.Port)
	fmt.Println(addr)
	RdbClient = redis.NewClient(&redis.Options{
		Addr:     addr,
		Password: "", // no password set
		DB:       0,  // use default DB
	})

	pong, err := RdbClient.Ping().Result()
	fmt.Println(pong, err)

	if err != nil {
		fmt.Println("redis连接失败：", err)
		logx.Error("连接失败")
		return
	}

	fmt.Println("redis连接ok")
}
